import 'package:eplorex/utils/ImagePickerUtils.dart';
import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';

class GalleryWidget extends StatefulWidget {
  GalleryWidget(
      {super.key,
      required this.initialIndex,
      required this.items,
      required this.isBarVisible});

  final int initialIndex;

  final List<FileWrapper> items;

  final bool isBarVisible;

  @override
  State<GalleryWidget> createState() => _GalleryWidgetState();
}

class _GalleryWidgetState extends State<GalleryWidget> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () => Navigator.pop(context),
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.transparent,
          elevation: 0,
        ),
        extendBodyBehindAppBar: true,
        backgroundColor: Colors.black,
        body: buildImageView(),
      ),
    );
  }

  Widget buildImageView() {
    return ExtendedImageGesturePageView.builder(
      controller: ExtendedPageController(
        initialPage: widget.initialIndex,
      ),
      itemCount: widget.items.length,
        itemBuilder: (BuildContext context, int index) {
      var item = widget.items[index];
      return ExtendedImage(
        image: AssetImage(item.file.path),
        fit: BoxFit.contain,
        mode: ExtendedImageMode.gesture,
        initGestureConfigHandler: (ExtendedImageState state) => GestureConfig(
            inPageView: true,
            initialScale: 1.0,
            speed: 1.0,
            //you can cache gesture state even though page view page change.
            //remember call clearGestureDetailsCache() method at the right time.(for example,this page dispose)
            cacheGesture: false),

      );
    });
  }
}
